<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="clr-namespace:System;assembly=mscorlib"
                    xmlns:wpfc="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
                    xmlns:local="clr-namespace:Suplex.Wpf">

    <Style TargetType="{x:Type local:TabControlOverflow}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TabControlOverflow}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:ValidationSummary}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:ValidationSummary}">
                    <Border Background="#99ff0000" BorderBrush="Red" BorderThickness=".5"
                            Visibility="{Binding ElementName=PART_ListBox, Path=Visibility, UpdateSourceTrigger=PropertyChanged}">
                        <StackPanel>
                            <TextBlock Text="Validation Errors:" Margin="2,1,0,1" />
                            <ListBox Name="PART_ListBox" Grid.Row="0" Grid.Column="1" BorderThickness="0" MaxHeight="100" Margin="1"
                                     ItemsSource="{Binding}"/>
                        </StackPanel>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <!-- ********************************************* SplxTreeListView ******************************************************* -->

    <local:LevelToIndentConverter x:Key="LevelToIndentConverter"/>

    <Style TargetType="{x:Type local:SplxTreeListViewItem}">

        <Setter Property="Panel.Background">
            <Setter.Value>
                <SolidColorBrush>#00FFFFFF</SolidColorBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.HorizontalContentAlignment">
            <Setter.Value>
                <Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource AncestorLevel=1, Mode=FindAncestor, AncestorType=ItemsControl}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Control.VerticalContentAlignment">
            <Setter.Value>
                <Binding Path="VerticalContentAlignment" RelativeSource="{RelativeSource AncestorLevel=1, Mode=FindAncestor, AncestorType=ItemsControl}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Padding">
            <Setter.Value>
                <Thickness>1,0,0,0</Thickness>
            </Setter.Value>
        </Setter>
        <Setter Property="TextElement.Foreground">
            <Setter.Value>
                <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
            </Setter.Value>
        </Setter>
        <Setter Property="FrameworkElement.FocusVisualStyle">
            <Setter.Value>
                <Style TargetType="IFrameworkInputElement">
                    <Style.Resources>
                        <ResourceDictionary />
                    </Style.Resources>
                    <Setter Property="Control.Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:SplxTreeListViewItem">
                    <StackPanel>
                        <Border BorderBrush="{TemplateBinding Border.BorderBrush}" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True" Padding="{TemplateBinding Control.Padding}">
                            <local:TreeGridViewRowPresenter x:Name="PART_Header"
                                                            FirstColumnIndent="{Binding Level, Converter={StaticResource LevelToIndentConverter}, RelativeSource={RelativeSource AncestorType={x:Type local:SplxTreeListViewItem}}, ConverterParameter=19}"
                                                            Content="{TemplateBinding Header}" 
                                                            Columns="{Binding Path=Columns, RelativeSource={RelativeSource AncestorType={x:Type local:SplxTreeListView}}}">
                                <local:TreeGridViewRowPresenter.Expander>
                                    <Grid>
                                        <ToggleButton Width="19" Height="16" ClickMode="Press" Name="Expander"
                                                      IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type local:SplxTreeListViewItem}}}">
                                            <ToggleButton.Style>
                                                <Style TargetType="ToggleButton">
                                                    <Style.Resources>
                                                        <ResourceDictionary />
                                                    </Style.Resources>
                                                    <Setter Property="UIElement.Focusable">
                                                        <Setter.Value>
                                                            <s:Boolean>False</s:Boolean>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Setter Property="FrameworkElement.Width">
                                                        <Setter.Value>
                                                            <s:Double>19</s:Double>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Setter Property="FrameworkElement.Height">
                                                        <Setter.Value>
                                                            <s:Double>13</s:Double>
                                                        </Setter.Value>
                                                    </Setter>
                                                    <Setter Property="Control.Template">
                                                        <Setter.Value>
                                                            <ControlTemplate TargetType="ToggleButton">
                                                                <Grid Width="15" Height="13" Background="Transparent">
                                                                    <Path Margin="1,1,1,1"
                                                                          Data="M 4 0 L 8 4 L 4 8 Z"
                                                                          Fill="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"
                                                                          Name="ExpandPath" />
                                                                </Grid>
                                                                <ControlTemplate.Triggers>
                                                                    <Trigger Property="ToggleButton.IsChecked">
                                                                        <Setter Property="Path.Data" TargetName="ExpandPath">
                                                                            <Setter.Value>
                                                                                <StreamGeometry>M 0 4 L 8 4 L 4 8 Z</StreamGeometry>
                                                                            </Setter.Value>
                                                                        </Setter>
                                                                        <Trigger.Value>
                                                                            <s:Boolean>True</s:Boolean>
                                                                        </Trigger.Value>
                                                                    </Trigger>
                                                                </ControlTemplate.Triggers>
                                                            </ControlTemplate>
                                                        </Setter.Value>
                                                    </Setter>
                                                </Style>
                                            </ToggleButton.Style>
                                        </ToggleButton>
                                    </Grid>
                                </local:TreeGridViewRowPresenter.Expander>
                            </local:TreeGridViewRowPresenter>
                        </Border>

                        <ItemsPresenter Name="ItemsHost" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="TreeViewItem.IsExpanded">
                            <Setter Property="UIElement.Visibility" TargetName="ItemsHost" Value="{x:Static Visibility.Collapsed}" />
                            <Trigger.Value>
                                <s:Boolean>True</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                        <Trigger Property="ItemsControl.HasItems">
                            <Setter Property="UIElement.Visibility" TargetName="Expander" Value="{x:Static Visibility.Hidden}" />
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                        <Trigger Property="TreeViewItem.IsSelected">
                            <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}" />
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.HighlightTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                            <Trigger.Value>
                                <s:Boolean>True</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="TreeViewItem.IsSelected">
                                    <Condition.Value>
                                        <s:Boolean>True</s:Boolean>
                                    </Condition.Value>
                                </Condition>
                                <Condition Property="TreeViewItem.IsSelectionActive">
                                    <Condition.Value>
                                        <s:Boolean>False</s:Boolean>
                                    </Condition.Value>
                                </Condition>
                            </MultiTrigger.Conditions>
                            <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.ControlTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                        </MultiTrigger>
                        <Trigger Property="UIElement.IsEnabled">
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>

    <Style x:Key="scroll">
        <Setter Property="UIElement.Focusable">
            <Setter.Value>
                <s:Boolean>False</s:Boolean>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid Background="{TemplateBinding Background}"
                SnapsToDevicePixels="true">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <DockPanel Margin="{TemplateBinding Padding}">
                            <ScrollViewer DockPanel.Dock="Top"
                            HorizontalScrollBarVisibility="Hidden"
                            VerticalScrollBarVisibility="Hidden"
                            Focusable="false">
                                <GridViewHeaderRowPresenter Columns="{Binding Path=Columns,RelativeSource={RelativeSource AncestorType={x:Type local:SplxTreeListView}}}"
                                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                            <ScrollContentPresenter Name="PART_ScrollContentPresenter"
                                      KeyboardNavigation.DirectionalNavigation="Local"
                                      Content="{TemplateBinding Content}"
                                      ContentTemplate="{TemplateBinding ContentTemplate}"
                                      CanContentScroll="{TemplateBinding CanContentScroll}"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </DockPanel>
                        <ScrollBar Name="PART_HorizontalScrollBar"
                       Orientation="Horizontal"
                       Grid.Row="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableWidth}"
                       ViewportSize="{TemplateBinding ViewportWidth}"
                       Value="{Binding Path=HorizontalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"
                       Cursor="Arrow"/>
                        <ScrollBar Name="PART_VerticalScrollBar"
                       Orientation="Vertical"
                       Grid.Column="1"
                       Minimum="0.0"
                       Maximum="{TemplateBinding ScrollableHeight}"
                       ViewportSize="{TemplateBinding ViewportHeight}"
                       Value="{Binding Path=VerticalOffset,RelativeSource={RelativeSource TemplatedParent},Mode=OneWay}"
                       Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                       Cursor="Arrow"/>
                        <DockPanel Grid.Column="1"
                       Grid.Row="1"
                       Background="{Binding Path=Background,ElementName=PART_VerticalScrollBar}"
                       LastChildFill="false">
                            <Rectangle DockPanel.Dock="Left"
                         Width="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                            <Rectangle DockPanel.Dock="Top"
                         Height="1"
                         Fill="White"
                         Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>
                        </DockPanel>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:SplxTreeListView}">
        <Setter Property="Panel.Background">
            <Setter.Value>
                <DynamicResource ResourceKey="{x:Static SystemColors.WindowBrushKey}" />
            </Setter.Value>
        </Setter>
        <Setter Property="Border.BorderBrush">
            <Setter.Value>
                <SolidColorBrush>#00FFFFFF</SolidColorBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Border.BorderThickness">
            <Setter.Value>
                <Thickness>2,2,2,2</Thickness>
            </Setter.Value>
        </Setter>
        <Setter Property="TextElement.Foreground">
            <Setter.Value>
                <DynamicResource ResourceKey="{x:Static SystemColors.WindowTextBrushKey}" />
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility">
            <Setter.Value>
                <x:Static Member="ScrollBarVisibility.Auto" />
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility">
            <Setter.Value>
                <x:Static Member="ScrollBarVisibility.Auto" />
            </Setter.Value>
        </Setter>
        <Setter Property="ScrollViewer.CanContentScroll">
            <Setter.Value>
                <s:Boolean>True</s:Boolean>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>

                <ControlTemplate TargetType="local:SplxTreeListView">
                    <wpfc:ClassicBorderDecorator BorderBrush="{TemplateBinding Border.BorderBrush}" BorderStyle="Sunken" BorderThickness="{TemplateBinding Border.BorderThickness}" Name="Bd" Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True">

                        <ScrollViewer Style="{StaticResource scroll}" Background="{TemplateBinding Background}"
                          Focusable="false"
                          CanContentScroll="false"
                          HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                          VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                          Padding="{TemplateBinding Padding}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                        </ScrollViewer>

                    </wpfc:ClassicBorderDecorator>

                    <ControlTemplate.Triggers>
                        <Trigger Property="UIElement.IsEnabled">
                            <Setter Property="Panel.Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
                            <Trigger.Value>
                                <s:Boolean>False</s:Boolean>
                            </Trigger.Value>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

    </Style>


    <Style TargetType="{x:Type TextBlock}" x:Key="SplxTreeGridSimpleStyle">
        <Setter Property="VerticalAlignment" Value="Center" />
    </Style>
    <Style TargetType="{x:Type TextBlock}" x:Key="SplxTreeGridBlockStyle">
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Visibility"
                Value="{local:FormattedBinding Path=IsSelected, ValueIfTrue=Hidden, ValueIfFalse=Visible,
                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SplxTreeListViewItem}}}" />
    </Style>
    <Style TargetType="{x:Type FrameworkElement}" x:Key="SplxTreeGridEditStyle">
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Visibility"
                Value="{local:FormattedBinding Path=IsSelected, ValueIfTrue=Visible, ValueIfFalse=Hidden,
                RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SplxTreeListViewItem}}}" />
    </Style>

</ResourceDictionary>
